﻿// -- ******************************************************************
// --       /\ /|       @file       $[InvalidReference].lua
// --       \ V/        @brief      await 29
// --       | "")       @author     Await, 285283010@qq.com
// --       /  |
// --      /  \\        @Modified   2024-11-20 15:11
// --    *(__\_\        @Copyright  Copyright (c) 2024-11-20 15:11, Await
// -- ******************************************************************

using Microsoft.AspNetCore.Authentication;

namespace AutomaticSubtitles.Service.Infrastructure.Extensions;

// public sealed class JwtBearerSecurityExtension(IAuthenticationSchemeProvider authenticationSchemeProvider): IOpenApiDocumentTransformer {
    // public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransformerContext context, CancellationToken cancellationToken) {
    //     var authenticationSchemes = await authenticationSchemeProvider.GetAllSchemesAsync();
    //     if (authenticationSchemes.Any(authScheme => authScheme.Name == "Bearer")) {
    //         // Add the security scheme at the document level
    //         var requirements = new Dictionary < string,
    //             OpenApiSecurityScheme > {
    //             ["Bearer"] = new OpenApiSecurityScheme {
    //                 Type = SecuritySchemeType.Http,
    //                 Scheme = "bearer", // "bearer" refers to the header name here
    //                 In = ParameterLocation.Header,
    //                 BearerFormat = "Json Web Token"
    //             }
    //         };
    //         document.Components ??= new OpenApiComponents();
    //         document.Components.SecuritySchemes = requirements;
    //
    //         // Apply it as a requirement for all operations
    //         foreach(var operation in document.Paths.Values.SelectMany(path => path.Operations)) {
    //             operation.Value.Security.Add(new OpenApiSecurityRequirement {
    //                 [new OpenApiSecurityScheme {
    //                     Reference = new OpenApiReference {
    //                         Id = "Bearer", Type = ReferenceType.SecurityScheme
    //                     }
    //                 }] = Array.Empty < string > ()
    //             });
    //         }
    //     }
    // }
// }